package thread;


public class Test {
    public static void main(String[] args) {
        Runnable r1 = ()-> {
            int sum = 0;
            for (int i = 1; i < 101; i+=2) {
                sum += i;
                System.out.println("奇数相加:"+sum);
            }
            System.out.println("奇数最后相加得:"+sum);
        };

        Runnable r2 = () -> {
            int sum = 0;
            for (int i = 2; i < 101; i+=2) {
                sum += i;
                System.out.println("偶数相加:"+sum);
            }
            System.out.println("偶数最后相加得:"+sum);
        };

        Thread t1 = new Thread(r1);
        Thread t2 = new Thread(r2);

        t1.start();
        t2.start();

        //超级简化版:
        Thread t3 = new Thread(()->{
            for (int i = 1, sum = 0; i < 101; System.out.println("奇数相加:"+(sum += i)), i+=2);
        });
        Thread t4 = new Thread(() -> {
            for (int i = 2, sum = 0; i < 101; System.out.println("偶数相加:"+(sum += i)), i+=2);
        });
        t3.start();
        t4.start();
    }
}
